package org.springframework.boot.autoconfigure.mock.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.mock.model.MockResTypeEnum;

import java.util.List;

/**
 * @author: hooware
 * @Date: 2021/12/26 17:32
 * @Description:
 */
public class MockResProcessorFactory {

    @Autowired
    private List<IMockResProcessor> mockResProcessorList;

    public IMockResProcessor pickMockResProcessor(MockResTypeEnum mockResTypeEnum) {
        return mockResProcessorList.stream()
                .filter(iMockResProcessor -> iMockResProcessor.match(mockResTypeEnum)).findFirst()
                .orElseThrow(() -> new IllegalArgumentException("mock response type is illegal, type: " + mockResTypeEnum));
    }

}
